package com.xm.xmapp.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.xm.xmapp.R;
import com.xm.xmapp.base.MyBaseAdapter;
import com.xm.xmapp.base.ViewHolder;
import com.xm.xmapp.response.bean.ResponseChargingPileList;
import com.xm.xmapp.response.bean.ResponseChargingPileList.E;

public class Charging_pile_listAdapter extends
		MyBaseAdapter<ResponseChargingPileList.E> {

	public interface PileOnclickInterFace {
		void start(E t);

		void item(E t);
	}

	private PileOnclickInterFace pileOnclickInterFace;

	public void setPileOnclickInterFace(
			PileOnclickInterFace pileOnclickInterFace) {
		this.pileOnclickInterFace = pileOnclickInterFace;
	}

	public Charging_pile_listAdapter(ArrayList<E> list, Activity activity,
			int layoutId) {
		super(list, activity, layoutId);
		
	}

	@Override
	public void setValues(ViewHolder holder, final E t, int position) {
	
		TextView id = (TextView) holder.getView(R.id.id);
	
		TextView status = (TextView) holder.getView(R.id.status);
		ImageView img = (ImageView) holder.getView(R.id.img);
		id.setText("编号：" + t.charging_equipment_interface_id);

		// 0=离网，1=空闲，2=占用（未充电），3=占用（充电中），4=占用（预约锁定），255=故障',
		status.setTextColor(0xff666666);
		switch (t.status) {
		case 1:

		case 2:
					
			status.setText(t.desc);				
			status.setTextColor(0xffF2cc1c);
			img.setImageResource(R.mipmap.startinput_icon);
			img.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (pileOnclickInterFace != null) {
						pileOnclickInterFace.start(t);
					} else {

					}

				}
			});
			break;
		case 3:
			status.setText("已被占用了，请选择其它桩。");
			img.setImageResource(R.mipmap.input_icon);
		
			img.setOnClickListener(null);
			break;
		case 0:

		case 4:

		case 255:
		
			status.setText("暂不可用，维护中。");
			img.setImageResource(R.mipmap.cant_icon);
			img.setOnClickListener(null);
			break;

		default:
			img.setOnClickListener(null);
			break;
		}
		
		
		holder.getConvertView().setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (pileOnclickInterFace != null) {
					pileOnclickInterFace.item(t);
				} else {

				}
				
			}
		});
	}
}
